#coding:utf-8
def Ma5_Val(str, val_type=""):
    #MD5加密,用于接口签名
    #默认小写，大写需要传upper
    import hashlib
    import types
    if type(str) is types.StringType:
        md5 = hashlib.md5()
        md5.update(str)
        if val_type == "upper":
            return md5.hexdigest().upper()
        else:
            return md5.hexdigest()
    else:
        return "errorCode: params must be str."


def Data_Key_Sort(data):
    #字典key排序,   用于接口签名
    #结果效果：aaa1a1bbcc
    result=sorted(data.items(), key=lambda item:item[0])
    test=""
    for i in result:
        test = test+ "".join(i)
    return test


def Key_Val_Sort(data):
    #字典key排序,用于接口签名
    #结果效果：a=a&a1=a1&b=b&c=c
    result=sorted(data.items(), key=lambda item:item[0])
    test = []
    for i in result:
        result = "=".join(i)
        test.append(result)

    return "&".join(test)

if __name__ == '__main__':
    pass